package com.mrjy.share.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.ShareApplyInfo;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.util.DateUtil;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.share.bo.IShareApplyBo;
/**
 * 分销申请 控制器
 * @author csshui
 *
 */
@Controller
@RequestMapping("/share/shareApply")
public class ShareApplyController {
	
	
	@Resource
	private IShareApplyBo shareApplyBo;
	
	/**
	 * 一级分销提交申请
	 * @param user
	 * @param session
	 * @return
	 */
	@RequestMapping("/applys")
	@ResponseBody
	public Object applys(UserInfo user,HttpSession session){
		Map<String,Object> map = new HashMap<String, Object>();
		UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if(userInfo != null){
			user.setId(userInfo.getId());
		}
		shareApplyBo.txApply(user , map);
		
		return map;
	}
	/**
	 * 查询申请状态
	 * @param sa
	 * @param session
	 * @return
	 */
	@RequestMapping("/queryApplyStatus")
	@ResponseBody
	public Object queryApplyStatus(ShareApplyInfo sa,HttpSession session){
		//UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);		
		shareApplyBo.queryApplyStatus(sa);
		return "ok";
	}
	/**
	 * 更新申请状态
	 * @param sa
	 * @param session
	 * @return
	 */
	@RequestMapping("/updateApplyStatus")
	@ResponseBody
	public Object updateApplyStatus(ShareApplyInfo sa,HttpSession session){
		//UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);		
		shareApplyBo.txApplyStatus(sa);
		return "ok";
	}
	
	/**
	 * 一级分销申请列表
	 * @param sa
	 * @return
	 */
	@RequestMapping("/listShareApplyInfo")
	@ResponseBody
	public Object listShareApplyInfo(ShareApplyInfo sa){		
		return shareApplyBo.listShareApplyInfo(sa);
	}
	
	
	/*@RequestMapping("/listShareCommisionInfo")
	@ResponseBody
	public Object listShareCommisionInfo(ShareApplyInfo sa){		
		return shareApplyBo.listShareCommisionInfo(sa);
	}*/
	/**
	 * 检查赚分享金用户为普通会员是否处于审核状态
	 * @param sa
	 * @return
	 */
	@RequestMapping("/checkUserAuditStatus")
	@ResponseBody
	public Object checkUserAuditStatus(ShareApplyInfo sa){
		Map<String,Object> map = new HashMap<String,Object>();
		shareApplyBo.checkUserAuditStatus(sa,map);
		return map;
	}
	/**
	 * 更新用户银行卡等信息
	 * @param user
	 * @param session
	 * @return
	 */
	@RequestMapping("/updateUserInfo")
	@ResponseBody
	public Object updateUserInfo(UserInfo user,HttpSession session){
		Map<String,Object> map = new HashMap<String, Object>();
		UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if(userInfo != null){
			user.setId(userInfo.getId());
			user.setModiferTime((new Date()).getTime());//保存修改时间
		}
		shareApplyBo.txUserInfo(user , map);
		
		return map;
	}
	/**
	 * 检查本月是否可以更新银行账号信息
	 * @param user
	 * @param session
	 * @return
	 */
	@RequestMapping("/isCanChange")
	@ResponseBody
	public Object isCanChange(UserInfo user,HttpSession session){
		Map<String,Object> map = new HashMap<String, Object>();
		UserInfo userInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if (null != userInfo) {
			user.setId(userInfo.getId());
		}
		shareApplyBo.isCanChange(user , map);
		
		return map;
	}
	
}
